/**
 * Description:
 * Class Name:DaemonThread
 * Date:2022/5/6 10:02
 *
 * @author LTisme
 * @version JAVA17
 */
package 疯狂Java讲义.第16章_多线程._16_4_控制线程._16_4_2_后台线程又名守护线程;

public class DaemonThread extends Thread{
    @Override
    public void run() {
        for (int i = 0; i < 1000; i++) {
            System.out.println(getName() + "_" + i);
        }
    }

    public static void main(String[] args) {
        DaemonThread t = new DaemonThread();
        // 将此线程设置成后台线程，并启动
        t.setDaemon(true);
        t.start();
        for (int i = 0; i < 10; i++) {
            System.out.println(Thread.currentThread().getName() + "_" + i);
        }
        // ----程序执行到此结束，前台线程（main线程）结束，后台线程也随之结束----
    }
}
